// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
/*导入 axios 模块*/
import axios from 'axios'
/*导入qs模块*/
import  qs from 'qs'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);

/*设置axios模块默认的url地址*/
axios.defaults.baseURL='/exam'

/*设置vue的全局变量*/
Vue.prototype.$http=axios;
Vue.prototype.$qs=qs;



Vue.config.productionTip = false

/*导航钩子*/
/*to:是要达到的下一个页面的路由对象*/
/*from:是从上一个页面来的路由对象*/
/*next :是一个函数，控制页面跳转的函数*/
router.beforeEach(function (to,from,next) {
    //获取sessionstorge的用户对象
    var user = localStorage.getItem("user");
    console.log("user="+user);
    console.log(to);
    //如果isLogin为true,需要拦截
    if(!to.meta.isLogin){
       //判断是否登录过
       if(user==null){
         //拦截，回到登录页面
         //next(路由地址)
         next("/")
       }else{
         next();
       }

    }else{//不拦截，放行
       next();
    }


})


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
